package com.jackfangqi.zhihuijizhou.activities;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.Window;

import com.jackfangqi.zhihuijizhou.R;
import com.jackfangqi.zhihuijizhou.constants.Constant;

public class SplashActivity extends Activity
        implements Runnable {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_splash);

        new Thread(this).start();
    }

    @Override
    public void run() {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        SharedPreferences preferences = getSharedPreferences(Constant.SP_NAME_APP, MODE_PRIVATE);
        PackageManager packageManager = getPackageManager();
        int versionCode = 1;
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
            versionCode = packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        boolean isShown = preferences.getBoolean(Constant.IS_SHOWN + versionCode, false);
        if (isShown)
            startActivity(new Intent(this, MainActivity.class));
        else
            startActivity(new Intent(this, TutorialActivity.class));

        this.finish();

    }
}
